package com.iknight.theory.service.impl;

import com.github.pagehelper.PageInfo;
import com.iknight.theory.api.TPTranPDeService;
import com.iknight.theory.mapper.TPTranPDeMapper;
import com.iknight.theory.model.TPTranPDeModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.Size;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TPTranPDeServiceImpl implements TPTranPDeService<TPTranPDeModel, String> {
    @Autowired
    private TPTranPDeMapper<TPTranPDeModel, String> tpTranPDeMapper;

    @Override
    public void save(TPTranPDeModel record) {

    }

    @Override
    public void delete(String pkey) {

    }

    @Override
    public TPTranPDeModel selectOne(String pkey) {
        return null;
    }

    @Override
    public PageInfo<TPTranPDeModel> selectPage(Map<String, Object> params, int pageStart, int pageSize) {
        return null;
    }

    @Override
    public Object getInfoByRecordId(String recordId) {
        Map result = new HashMap();

        Map params = new HashMap();
        params.put("record_id", recordId);
        List<TPTranPDeModel> resultLs = tpTranPDeMapper.selectByCond(params);
        if (resultLs.size() > 0) {
            TPTranPDeModel model = resultLs.get(0);
            Map k1Map = new HashMap();
            Map k2Map = new HashMap();
            Map k3Map = new HashMap();
            k1Map.put("lossPower", model.getLoss_k1());
            k2Map.put("lossPower", model.getLoss_k2());
            k3Map.put("lossPower", model.getLoss_k3());

            k1Map.put("lossRate", model.getRate_k1());
            k2Map.put("lossRate", model.getRate_k2());
            k3Map.put("lossRate", model.getRate_k3());

            k1Map.put("kValue", model.getValue_k1());
            k2Map.put("kValue", model.getValue_k2());
            k3Map.put("kValue", model.getValue_k3());

            result.put("currentAvg", model.getCurrent_avg());
            result.put("currentMax", model.getCurrent_max());
            result.put("consLineLoss", model.getLoss_consline());
            result.put("segLineLoss", model.getLoss_baseseg());

            result.put("caseK1", k1Map);
            result.put("caseK2", k2Map);
            result.put("caseK3", k3Map);
        }
        return result;
    }
}
